import { AxiosError } from 'axios'
import AxiosRequestError, { ErrorResponse } from './error'

export function handleError(error: AxiosError | AxiosRequestError): AxiosRequestError {
	const err =
		error instanceof AxiosRequestError
			? error
			: new AxiosRequestError(error.response?.status || 1, error.message, error, error.response?.data as ErrorResponse)
	return err
}
